/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package actions;

import com.paris5.master2.guitarmaster.bean.EcomBid;
import com.paris5.master2.guitarmaster.bean.EcomProduct;
import com.paris5.master2.guitarmaster.exception.EcomQueryException;
import com.paris5.master2.guitarmaster.service.ServiceProductRemote;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alice
 */
public class AfficheEnchere extends EcomAction {

    private List<EcomProduct> enchereProducts;
    private int countEnchereProducts;
    private EcomBid bid;
    private List<EcomBid> listLastBibProduct;
    
    public List<EcomProduct> getEnchereProducts() {
        return enchereProducts;
    }
    
    public void setEnchereProducts(List<EcomProduct> enchereProducts) {
        this.enchereProducts = enchereProducts;
    }
    
    public int getCountEnchereProducts() {
        return countEnchereProducts;
    }
    
    public void setCountEnchereProducts(int countEnchereProducts) {
        this.countEnchereProducts = countEnchereProducts;
    }

    public EcomBid getBid() {
        return bid;
    }

    public void setBid(EcomBid bid) {
        this.bid = bid;
    }

    public List<EcomBid> getListLastBibProduct() {
        return listLastBibProduct;
    }

    public void setListLastBibProduct(List<EcomBid> listLastBibProduct) {
        this.listLastBibProduct = listLastBibProduct;
    }
    
    @Override
    public String execute() {
        try {
            ServiceProductRemote serviceProductRemote = lookupServiceProductRemote();
            enchereProducts = serviceProductRemote.getAllProductsInBid(0, 10, 1, true);
            countEnchereProducts = serviceProductRemote.countAllProductsInBid();
            listLastBibProduct = new ArrayList<EcomBid>();
            
            if (enchereProducts == null) {
                setMessage("Aucune enchère en cours.");
            }else{ 
                for (int z=0;z<enchereProducts.size();z++){
                    bid = serviceProductRemote.getLastProductPriceInBid(enchereProducts.get(z),1,true);
                    listLastBibProduct.add(z,bid);        
                }
                setMessage("Produit en enchère ("+countEnchereProducts+")");
            }
            registerRate();
            return SUCCESS;
        } catch (EcomQueryException ex) {
            Logger.getLogger(AfficheEnchere.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ERROR;
    }
}
